<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="format-detection" content="telephone=no, address=no, email=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no" />
		<meta name="HandheldFriendly" content="true" />
		<title>添加渠道未代理</title>
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />

	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">添加渠道</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group group-form ease transition" id="group-form">
				<div class="mui-input-row" style="background:none">
					<label>姓名</label>
					<input type="text" class="mui-input-clear mui-disabled" id="ename" disabled="true" name="ename" placeholder="请填写姓名" value="">
				</div>
				<div class="mui-input-row" style="background:none">
					<label>电话</label>
					<input type="text" class="mui-input-clear  mui-disabled" id="etel" disabled="true" name="etel" placeholder="请填写电话" value="">
				</div>
				<div class="mui-input-row">
					<label>公司</label>
					<input type="text" class="mui-input-clear" id="ecompany" name="ecompany" placeholder="请填写公司" value="">
				</div>
				<div class="mui-input-row">
					<label>地址</label>
					<input type="text" class="mui-input-clear" id="eaddress" placeholder="请填写地址" value="">
				</div>
				<div class="mui-input-row">
					<label>产品</label>
					<div class="div-select-container">
						<select id="jd" style="padding-left:5px;"></select>
					</div>

				</div>
				<div class="mui-input-row">
					<label>代理地区</label>
					<input type="text" class="mui-input-clear" id="ereplace" placeholder="请填写代理地区" value="">
				</div>
				<div class="mui-input-row">
					<label>备注</label>
					<input type="text" class="mui-input-clear" id="enote" placeholder="请填写备注" value="">
				</div>

				<div class="mui-button-row" style="margin-top:0.5rem">
					<button type="button" class="mui-btn mui-btn-primary mui-btn-full" id="nextStep" style="height:44px;background:#f1c40f;color:#fff;border-color:#f1c40f">提交</button>
				</div>

			</form>
		</div>
	</body>
	<script src="../../js/resize.js"></script>
	<script src="../../js/mui.min.js"></script>
	<script src="../../js/app.js"></script>
	<script src="../../js/ajaxFun.js"></script>
	<script src="../../js/jxs.js"></script>
	<!--<script type="text/javascript" src="js/update.js"></script>-->
	<script>
		var data = {
			address: '',
			area: '',
			companyName: '',
			mobile: '',
			name: '',
			productNo: '',
			remark: '',
		};
		var abutton = document.getElementById("nextStep");
		var messageObj = document.getElementById("message");
		(function($, doc) {
			$.plusReady(function() {
				plus.nativeUI.closeWaiting();
				Dealers.getProduct(); //获取经销商代理的产品
				var currentView = plus.webview.currentWebview();
				document.getElementById("ename").value  = currentView.name?currentView.name:'';
				document.getElementById("etel").value  = currentView.mobile?currentView.mobile:'';
				abutton.addEventListener('tap', addJXS);
			})
		}(mui, document))

		function addJXS() {
			var ename = document.getElementById("ename").value;
			var etel = document.getElementById("etel").value;
			var ecompany = document.getElementById("ecompany").value;

			var eaddress = document.getElementById("eaddress").value;
			var ereplace = document.getElementById("ereplace").value;
			var enote = document.getElementById("enote").value;
			var productNo = document.getElementById("jd").value;
			if(!ename) {
				plus.nativeUI.alert('用户名不能为空');
				return false;
			} else if(ename.length >10) {
				plus.nativeUI.alert('用户名不得超过10个字');
				return false;
			} else if(testStr(ename)){
				plus.nativeUI.alert('用户名不得包含非法字符');
				return false;
			}

			if(!etel) {
				plus.nativeUI.alert('手机号码不能为空');
				return false;
			} else if(!app.checkTel(etel)) {
				plus.nativeUI.alert('手机号码格式不正确');
				return false;
			}

			if(!ecompany) {
				plus.nativeUI.alert('请填写公司名称');
				return false;
			} else if(ecompany.length > 50) {
				plus.nativeUI.alert('公司名称不得超过50个字');
				return false;
			}else if(testStr(ecompany)){
				plus.nativeUI.alert('公司名称不得包含非法字符');
				return false;
			}

			if(!eaddress) {
				plus.nativeUI.alert('请填写地址');
				return false;
			} else if(eaddress.length > 50) {
				plus.nativeUI.alert('地址不得超过50个字');
				return false;
			}else if(testStr(eaddress)){
				plus.nativeUI.alert('地址不得包含非法字符');
				return false;
			}

			if(!ereplace) {
				 
			} else if(ereplace.length > 50) {
				plus.nativeUI.alert('代理地区不得超过50个字');
				return false;
			}else if(testStr(ereplace)){
				plus.nativeUI.alert('代理地区不得包含非法字符');
				return false;
			}

			if(!enote) {
				
			} else if(enote.length > 50) {
				plus.nativeUI.alert('备注不得超过50个字');
				return false;
			}else if(testStr(enote)){
				plus.nativeUI.alert('备注不得包含非法字符');
				return false;
			}

			if(!productNo) {
				plus.nativeUI.alert('请选择代理产品！');
				return false;
			}
			data.address = eaddress;
			data.area = ereplace,
				data.companyName = ecompany,
				data.mobile = etel,
				data.name = ename,
				data.productNo = productNo,
				data.remark = enote;
				abutton.removeEventListener('tap', addJXS);	
				setTimeout(function(){
					var addUrl = baseUrl + 'dealersController/saveDealer.do';
					ajaxFun.postFun(addUrl, data, '', function(d) {
						plus.nativeUI.alert(d.msg,function(){
							abutton.addEventListener('tap', addJXS);
							abutton.style.backgroundColor='#f1c40f'; abutton.style.borderColor='#f1c40f';
							openWindow('index.html','main-jxs');
						});
					},function(d){
						plus.nativeUI.alert(d.msg,function(){
							abutton.addEventListener('tap', addJXS);
							abutton.style.backgroundColor='#f1c40f'; abutton.style.borderColor='#f1c40f';
						});
					})
				},100)
		}
		
		
	</script>

</html>